﻿Imports Oracle.DataAccess.Client
Public Class fListaCanales
    Private lIdCanal As String
    Private daListas As lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
    Public ReadOnly Property Canal() As String
        Get
            Return lIdCanal
        End Get
    End Property
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        Dim qWhere As String = ""
        If Me.txtCanal.Text.Trim.Length > 0 Then
            qWhere = "WHERE DESCRIPCION LIKE '%" & Me.txtCanal.Text & "%'"
        End If
        cmd.CommandText = "SELECT * FROM FAC_CANALES " & qWhere
        Try
            Conn.Open()
            DsFacturacion.FAC_CANALES.Rows.Clear()
            DsFacturacion.FAC_CANALES.Load(cmd.ExecuteReader)
            Conn.Close()
            FAC_CANALESDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub
    Private Sub CargaLista()
        Try
            daListas.Fill(DsProductos.PRO_ENCALISTAPRECIOS)

            Dim Dr As lbGlobalcom.dsProductos.PRO_ENCALISTAPRECIOSRow = DsProductos.PRO_ENCALISTAPRECIOS.NewPRO_ENCALISTAPRECIOSRow
            Dr.IDLISTA = "-1"
            Dr.DESCRIPCION = "Todas"
            Dr.ESTADO = 16
            DsProductos.PRO_ENCALISTAPRECIOS.Rows.Add(Dr)
            Dr = Nothing
            cbListas.SelectedValue = "-1"
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub
 

    Private Sub FAC_CANALESDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles FAC_CANALESDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lIdCanal = FAC_CANALESDataGridView.Rows(e.RowIndex).Cells("IDCANAL").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub fListaCanales_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daListas = New lbGlobalcom.dsProductosTableAdapters.PRO_ENCALISTAPRECIOSTableAdapter
            Me.CargaLista()
            Me.cbListas.Text = "Todas"
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub
    Private Sub AsignaCanal(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIdCanal = FAC_CANALESDataGridView.Rows(Fila).Cells("IDCANAL").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub FAC_CANALESDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles FAC_CANALESDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaCanal(FAC_CANALESDataGridView.CurrentRow.Index)
        End If
    End Sub
End Class